package org.example.controller;

import io.seata.spring.annotation.GlobalTransactional;
import org.example.feign.RoomFeign;
import org.example.feign.TypeFeign;
import org.example.pojo.Room;
import org.example.pojo.Type;
import org.example.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/roomFeign")
public class RoomController {
    @Resource
    private RoomFeign roomFeign;
    @Resource
    private TypeFeign typeFeign;
    //    房间列表
    @GetMapping("/listRoom")
    public Result listRoom(){
        return Result.OK(roomFeign.listRoom());
    }
    //    房间的逻辑删除
    @PostMapping("/del")
    public Result del(@RequestParam("rid") Integer rid){
        return Result.OK(roomFeign.del(rid));
    }
    @GlobalTransactional
    @PostMapping("/add")
    public Result buy(@RequestBody Room room){
        System.out.println(room);
        Boolean add = roomFeign.add(room);
        int i = 9/0;
        if(add){
            Type type=new Type();
            typeFeign.updateNum(room.getTid(),type.getAmount()+1);
            return Result.OK("成功");
        }
        return Result.ERROR("失败");
    }
}
